package com.iran.protoType.javaCloneable;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Objects;
/*Cloneable 是一个标识接口没有任何方法，但是Object类中的clone是保护方法，并且是一个native方法，只有继承了Cloneable才能将该方法重写为public,不然会报错*/

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class Person implements Cloneable {
    private String name;
    private String sex;
    private int age;
    private Address address;

    /**
     * 浅拷贝
     * @return
     * @throws CloneNotSupportedException
     */
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Person person = (Person) super.clone();
        if (address!=null) {
            person.address = (Address) address.clone();
        }
        return person;
    }


}
